package com.micro.service.controller;

import com.micro.service.annotation.ApiVersion;
import com.micro.service.entity.ResponseMessage;
import com.micro.service.model.UserArticle;
import com.micro.service.rpc.RpcUserArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by Vic Xu on 2019/3/24
 */
@RestController
@ApiVersion(1)
@RequestMapping("{version}/user/article")
public class RpcUserArticleController {

    @Autowired
    private RpcUserArticle rpcUserArticle;

    @GetMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<List<UserArticle>> getAll() {
        return rpcUserArticle.getAll();
    }

    @PostMapping(value = "one", produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<List<UserArticle>> findByCardId(@RequestBody UserArticle userArticle) {
        return rpcUserArticle.findByCardId(userArticle);
    }

    @PostMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<UserArticle> saveUserArticle(@RequestBody UserArticle userArticle) {
        return rpcUserArticle.saveUserArticle(userArticle);
    }

    @PutMapping(produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<UserArticle> updateUserArticle(@RequestBody UserArticle userArticle) {
        return rpcUserArticle.updateUserArticle(userArticle);
    }

    @DeleteMapping(value = "{id}", produces = {"application/json;charset=UTF-8"})
    public ResponseMessage<String> deleteUserArticle(@PathVariable("id") String id) {
        return rpcUserArticle.deleteUserArticle(id);
    }

}
